#ifndef _VS_OBJECT_H
#define _VS_OBJECT_H

#include "Shape.h"
#include "Point3D.h"
#include <gl\glut.h>
#include "Gravity.h"

class VSObject
{
public:
	enum RENDER_TYPE{USE_NOTHING,USE_COLOR,USE_MAT};
	VSObject(float x=0,float y=0,float z=0,float l=1,float w=1,float h=1,GLfloat rotateAngle = 0,Point3D rotateAxis = Point3D(0,0,0));
	~VSObject(void);
	void render(float * ground = NULL);
	bool isBoundingBox(Point3D pos,Point3D size);
	bool isBoundingBox(Point3D pos);
	bool isBoundingBoxwithZ(Point3D pos);
	void boundingbox(float & length,float & width, float & height);
	void center(float & x,float & y, float & z);

	VSObject setShape(int shape,int mode = Shape::WIRE);
	VSObject setColor(float color[]);
	VSObject setMat(float mat[]);

public:
	void Move(Point3D direction);
	void Scale(Point3D direction);
	void Rotate(Point3D moves1p1,Point3D moves1p2,Point3D moves2p1,Point3D moves2p2);
	void Rotate(Point3D axis,double angle);
	float z(){return m_z;}
	float y(){return m_y;}
	float x(){return m_x;}
	void setX(float x);
	void setY(float y);
	void setZ(float z);
	void setL(float l);
	void setW(float w);
	void setH(float h);
	void setRotate(GLfloat rotateAngle,Point3D rotateAxis);
	float h(){return m_h;}
	float l(){return m_l;}
	float w(){return m_w;}
	void select(int handIdx){m_selecteNo = handIdx;}
	void deselect(){m_selecteNo = -1;}
	int selectNo(){return m_selecteNo;}
	VSObject setGravity(bool g);
	void setMerge(int m){m_mergeNo = m;}
	void addMerge(){++m_mergeNo;}

	bool operator == (VSObject v);

private:
	Shape m_shape;
	float m_x;
	float m_y;
	float m_z;
	float m_l;
	float m_w;
	float m_h;
	GLfloat m_rotateAngle;
	//int m_rotateAxis;
	Point3D m_rotateAxis;
	void angle(Point3D pt1, Point3D pt2 );
	int m_selecteNo;
	float m_mat[4];
	float m_color[4];
	RENDER_TYPE m_renderType;
	bool m_bGravity;
	int m_mergeNo;
	Gravity * m_gravity;
	glm::mat4 m_rotate;

public:
	GLint    viewport[4]; 
	GLdouble modelview[16]; 
	GLdouble projection[16]; 

};

#endif